/* Singleton design pattern
 *
 * reference: http://sourcemaking.com/design_patterns/singleton/cpp/2
 * 
 * 1. Define a private static attribute in the "single instance" class
 * 2. Define a public static accessor function in the class
 * 3. Do "lazy initialization" (creation on demand) in the accessor function
 * 4. Define all constructors to be protected or private
 * 5. Clients may only use the accessor function to manipulate the Singleton
 * 6. Inheritance can be supported, but static functions may not be overridden. The base class must be declared a friend of the derived class (in order to access the protected constructor).
 *
 */

class Number
{
  public:
    //2. Define a public static accessor function in the class
    static Number *instance()
    {
      if (inst == NULL)
      {
        inst = new Number();
      }
      return inst;
    }

    int getValue()
    {
      return this->value;
    }

    void setValue(int v)
    {
      this->value = v;
    }

  private:
    Number()
    {
      
    }
    
    int value;
    static Number *inst;
};

Number *Number::inst = NULL;

int main()
{
  
}
